package com.cskaoyan.service;

import com.cskaoyan.bean.BaseParam;

import com.cskaoyan.bean.user.Footprint;
import com.cskaoyan.bean.user.FootprintExample;
import com.cskaoyan.bean.BaseData;

import com.cskaoyan.bean.user.FootprintVo;
import com.cskaoyan.mapper.FootprintMapper;
import com.cskaoyan.util.PageUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * \* Description:
 * \
 */
@Service
public class FootprintServiceImpl implements FootprintService {

    @Autowired
    FootprintMapper footprintMapper;

    @SuppressWarnings("all")
    @Override
    public BaseData<FootprintVo> footprint(BaseParam param, Integer userId, Integer goodsId) {
        PageUtil.start(param);
        FootprintExample footprintExample = new FootprintExample();
        footprintExample.setOrderByClause(param.getSort() + " " + param.getOrder());
        FootprintExample.Criteria criteria = footprintExample.createCriteria();

        if (userId != null && !"".equals(userId))
            criteria.andUserIdEqualTo(userId);
        if (goodsId != null && !"".equals(goodsId))
            criteria.andGoodsIdEqualTo(goodsId);
        List<Footprint> footprintList = footprintMapper.selectByExample(footprintExample);
        ArrayList<FootprintVo> footprintVos = new ArrayList<>();
        for (Footprint footprint : footprintList) {
            FootprintVo footprintVo = new FootprintVo(footprint);
            footprintVos.add(footprintVo);
        }
        PageInfo<FootprintVo> footprintVoPageInfo = new PageInfo<>(footprintVos);
        BaseData<FootprintVo> footprintBaseData = new BaseData<>(footprintVoPageInfo, footprintVos);

        return footprintBaseData;
    }
}
